package binance.controller
import binance.model.*

class SearchController {

    def show = {
        log.debug "show"
    }

    def results = {
        log.debug "results"
        if (params['query']) {
            String query = params['query']
            String queryStr = "from Stock as s where s.code like '%${query}%' or s.name like '%${query}%'"
            results = Stock.findAll(queryStr,[max:15])
            log.debug "Found ${query} : ${results.size()}"
            return [query:query,results:results]
        }else{
            render(text:"")
        }
    }

    def result = {
        [stock:Stock.findById(params['id'])]
    }
}
